<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约订单管理</title>
    <link rel="stylesheet" href="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/css/layui.css">
    <style>
        .layui-table-cell{
            height:36px;
            line-height: 36px;
        }
        .layui-col-xs1{
            height: 66px;
            line-height: 66px;
            margin: 5px 5px 0 0;
            text-align: center;
            font-size: 20px;
            cursor: pointer;
        }
        .info{
            font-size: 14px;
            color: rgb(110, 108, 108);
            line-height: 36px;
        }
        .layui-icon-search{
            font-size: 30px;
            color: #009688;
            cursor: pointer;
            margin-left: 40px;
        }
        
    </style>
</head>
<body>
    <table id="demo" lay-filter="test"></table>


<!-- 订单详细页面 -->
    <div id="orderDetails" style="display: none;">
        <div class="layui-form-item">
            <label class="layui-form-label">订单号</label>
            <div class="layui-input-block id_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block userid_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">买家编号</label>
            <div class="layui-input-block buyerid_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单时间</label>
            <div class="layui-input-block createdate_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单状态</label>
            <div class="layui-input-block orderstatus_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">付款方式</label>
            <div class="layui-input-block paymethod_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">付款订单</label>
              <div class="layui-input-inline payorderid_info1 info"></div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">付款时间</label>
              <div class="layui-input-inline paydate_info1 info"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">机器ID</label>
              <div class="layui-input-inline machineid_info1 info"></div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">格子柜号</label>
              <div class="layui-input-inline containernumber_info1 info"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单总价</label>
            <div class="layui-input-block amount_info1 info"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block comment_info1 info"></div>
        </div>

        <table class="layui-table" lay-skin="line">
            <thead>
                <tr>
                  <th>商品名称</th>
                  <th>商品规格</th>
                  <th>商品单价</th>
                  <th>商品数量</th>
                </tr> 
            </thead>
            <tbody id="commodities_info1"></tbody>
        </table>

    </div>




    <script type="text/html" id="barDemo">
        <i class="layui-icon layui-icon-tabs" lay-event="orderDetails_1" title="订单详情"></i>
    </script>

    <script type="text/html" id="toolbarDemo">
        
        <div class="layui-inline" style="width: 150px;">
            <select name="payMethod_2" lay-verify="" id="payMethod_2">
                <option value="" id="payMethod_2_2">付款方式</option>
                <option value="0">支付宝</option>
                <option value="1">微信</option>
            </select>
        </div>
        <div class="layui-inline" style="width: 150px;">
            <select name="status_2" lay-verify="" id="status_2">
                <option value="" id="status_2_2">订单状态</option>
                <option value="0">未付款</option>
                <option value="1">未发货</option>
                <option value="2">未取货</option>
                <option value="3">订单完成</option>
            </select>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 150px;">
              <input type="text" name="orderId_2" id="orderId_2" placeholder="输入订单号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 150px;">
              <input type="text" name="machineId_2" id="machineId_2" placeholder="输入机器ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 150px;">
              <input type="text" name="userid_2" id="userid_2" placeholder="输入用户ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <div class="layui-input-inline" style="width: 120px;">
                <input type="text" name="createdateStart_2" id="createdateStart_2" placeholder="订单起始时间" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid">-</div>
              <div class="layui-input-inline" style="width: 120px;">
                <input type="text" name="createdateEnd_2" id="createdateEnd_2" placeholder="订单结束时间" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 120px;">
                  <input type="text" name="paydateStart_2" id="paydateStart_2" placeholder="付款起始时间" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 120px;">
                  <input type="text" name="paydateEnd_2" id="paydateEnd_2" placeholder="付款结束时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <i class="layui-icon layui-icon-search" lay-event="getBookOrderListSearch_2" title="搜索刷新"></i>
            </div>
        </div>
        
    </script>


    
   
    <script src="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/layui.js"></script>
    <script>
        
        
        
        

        layui.use(['table','laydate','form','util'], function(){
            var $ = layui.jquery;
            var table = layui.table;
            var laydate =layui.laydate;
            var form = layui.form
            var util = layui.util;

            table.render({
                elem: '#demo',
                height: 'full-60',
                method: 'post',
                url: '/admin/bookOrderAdmin/getBookOrderList', //数据接口
                page: true, //开启分页
                toolbar: '#toolbarDemo',
                defaultToolbar: [],
                id: 'adTest',
                cols: [[ //表头
                {field: 'user_id', title: '用户ID', width:'15%', sort: true, fixed: 'left'},
                {field: 'id', title: '订单号', width:'20%',},
                {field: 'create_date', title: '订单时间', templet:"<div>{{layui.util.toDateString(Number(d.create_date), 'yyyy.MM.dd HH:mm:ss')}}</div>", width:'15%', sort: true},
                {field: 'machine', title: '机器ID', templet:'<div>{{d.machine.id}}</div>', width:'10%'} ,
                {field: 'pay_method', title: '付款方式', templet:'<div>{{paymethodfun(d.pay_method)}}</div>', width: '15%'},
                {field: 'order_status', title: '订单状态', width: '10%', templet:'<div>{{orderstatusfun(d.order_status)}}</div>', sort: true},
                {field: 'amount', title: '订单金额', width: '10%', sort: true},
                {fixed: 'right', width:'5%', align:'center', toolbar: '#barDemo'}
                ]],


                parseData: function(res){ //res 即为原始返回的数据
                    return {
                    "code": res.success, //解析接口状态
                    "msg": res.message, //解析提示文本
                    // "count": res.data.total, //解析数据长度
                    "data": res.data //解析数据列表
                    };
                },
                request: {
                    pageName: 'pageNum', //页码的参数名称，默认：page
                    // limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                response: {
                    // statusName: 'success', //规定数据状态的字段名称，默认：code
                    statusCode: true //规定成功的状态码，默认：0
                }
            });
            laydate.render({
                elem: '#createdateStart_2',
                format: 'yyyy/MM/dd',
            });
            laydate.render({
                elem: '#createdateEnd_2',
                format: 'yyyy/MM/dd'
            });
            laydate.render({
                elem: '#paydateStart_2',
                format: 'yyyy/MM/dd'
            });
            laydate.render({
                elem: '#paydateEnd_2',
                format: 'yyyy/MM/dd'
            });
        
            table.on('toolbar(test)', function(obj){
                sessionStorage.setItem("payMethod_2_1", $("#payMethod_2").val());
                sessionStorage.setItem("status_2_1", $("#status_2").val());
                sessionStorage.setItem("machineId_2_1", $("#machineId_2").val());
                sessionStorage.setItem("userid_2_1", $("#userid_2").val());
                sessionStorage.setItem("orderId_2_1", $("#orderId_2").val());
                sessionStorage.setItem("createdateStart_2_1", $("#createdateStart_2").val());
                sessionStorage.setItem("createdateEnd_2_1", $("#createdateEnd_2").val());
                sessionStorage.setItem("paydateStart_2_1", $("#paydateStart_2").val());
                sessionStorage.setItem("paydateEnd_2_1", $("#paydateEnd_2").val());
                //搜索栏的实现
                switch(obj.event){
                    case 'getBookOrderListSearch_2':
                    if ($("#userid_2").val() != '') {
                        var userid = $("#userid_2").val()
                    }else{
                        var userid = undefined
                    }
                    
                    table.reload('adTest', {
                        where: { //设定异步数据接口的额外参数，任意设
                            payMethod: $("#payMethod_2 option:selected").attr('value'),
                            status: $("#status_2 option:selected").attr('value'),
                            user_id: userid,
                            machineId: $("#machineId_2").val(),
                            orderId: $("#orderId_2").val(),
                            create_date_start: dateTime($("#createdateStart_2").val()),
                            create_date_end: dateTime($("#createdateEnd_2").val()),
                            pay_date_start: dateTime($("#paydateStart_2").val()),
                            pay_date_end: dateTime($("#paydateEnd_2").val())
                        },
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                    });
                    laydate.render({
                        elem: '#createdateStart_2',
                        format: 'yyyy/MM/dd',
                    });
                    laydate.render({
                        elem: '#createdateEnd_2',
                        format: 'yyyy/MM/dd'
                    });
                    laydate.render({
                        elem: '#paydateStart_2',
                        format: 'yyyy/MM/dd'
                    });
                    laydate.render({
                        elem: '#paydateEnd_2',
                        format: 'yyyy/MM/dd'
                    });

                    // $("#payMethod_2 option[value= payMethod_2_1 ]").attr("selected","selected");
                    if (sessionStorage.getItem("payMethod_2_1") == '') {
                        $("#payMethod_2_2").attr('text','付款方式')
                    }else if(sessionStorage.getItem("payMethod_2_1") == '0'){
                        $("#payMethod_2 option[value= '0']").attr("selected", true);
                    }else if (sessionStorage.getItem("payMethod_2_1") == '1') {
                        $("#payMethod_2 option[value= '1']").attr("selected", true);
                    }

                    if (sessionStorage.getItem("status_2_1") == '') {
                        $("#status_2").attr('text','订单状态')
                    }else if(sessionStorage.getItem("status_2_1") == '0'){
                        $("#status_2 option[value= '0']").attr("selected", true);
                    }else if (sessionStorage.getItem("status_2_1") == '1') {
                        $("#status_2 option[value= '1']").attr("selected", true);
                    }else if (sessionStorage.getItem("status_2_1") == '2') {
                        $("#status_2 option[value= '2']").attr("selected", true);
                    }else if (sessionStorage.getItem("status_2_1") == '3') {
                        $("#status_2 option[value= '3']").attr("selected", true);
                    }

                    // if (sessionStorage.getItem("status_2_1") == '') {
                    //     $("#status_2").attr('text','订单状态')
                    // }else{
                    //     $("#status_2 option[value= status_2_1]").attr("selected", true);
                    // }




                    if (sessionStorage.getItem("machineId_2_1") == '') {
                        $("#machineId_2").attr('placeholder','输入机器ID')
                    }else{
                        $("#machineId_2").attr('placeholder',sessionStorage.getItem("machineId_2_1"))
                    }
                    if (sessionStorage.getItem("userid_2_1") == '') {
                        $("#userid_2").attr('placeholder','输入用户ID')
                    }else{
                        $("#userid_2").attr('placeholder',sessionStorage.getItem("userid_2_1"))
                    }
                    if (sessionStorage.getItem("orderId_2_1") == '') {
                        $("#orderId_2").attr('placeholder','输入订单号')
                    }else{
                        $("#orderId_2").attr('placeholder',sessionStorage.getItem("orderId_2_1"))
                    }
                    if (sessionStorage.getItem("createdateStart_2_1") == '') {
                        $("#createdateStart_2").attr('placeholder','订单起始时间')
                    }else{
                        $("#createdateStart_2").attr('placeholder',sessionStorage.getItem("createdateStart_2_1"))
                    }
                    if (sessionStorage.getItem("createdateEnd_2_1") == '') {
                        $("#createdateEnd_2").attr('placeholder','订单结束时间')
                    }else{
                        $("#createdateEnd_2").attr('placeholder',sessionStorage.getItem("createdateEnd_2_1"))
                    }
                    if (sessionStorage.getItem("paydateStart_2_1") == '') {
                        $("#paydateStart_2").attr('placeholder','付款起始时间')
                    }else{
                        $("#paydateStart_2").attr('placeholder',sessionStorage.getItem("paydateStart_2_1"))
                    }
                    if (sessionStorage.getItem("paydateEnd_2_1") == '') {
                        $("#paydateEnd_2").attr('placeholder','付款结束时间')
                    }else{
                        $("#paydateEnd_2").attr('placeholder',sessionStorage.getItem("paydateEnd_2_1"))
                    }
                    
                    break;
                };
            });

            table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                if(layEvent === 'orderDetails_1'){
                    $.ajax({
                        type: "post",
                        url: "/admin/bookOrderAdmin/getOrderDetail",
                        data: {order_id: data.id},
                        dataType: "json",
                        async: false,
                        success: function(mag){
                            $(".id_info1").html('<span style="color: #f173e1;">'+mag.data.id+'</span>')
                            $(".userid_info1").html(mag.data.user.name)
                            $(".buyerid_info1").html(status(mag.data.buyer_id))
                            $(".createdate_info1").html(ctime(mag.data.create_date))
                            $(".orderstatus_info1").html(orderstatusfun(mag.data.order_status))
                            $(".machineid_info1").html(mag.data.machine_id)
                            $(".containernumber_info1").html(status(mag.data.container_number))
                            $(".amount_info1").html('<span style="color: #f173e1;">'+mag.data.amount+'</span>')
                            $(".comment_info1").html(mag.data.comment)
                            $(".paymethod_info1").html(paymethodfun(mag.data.pay_method))
                            $(".payorderid_info1").html(status(mag.data.pay_order_id))
                            $(".paydate_info1").html(ctime(mag.data.pay_date))
                            var commodities = mag.data.commodities
                            if (commodities.length != 0) {
                                var flag = ''
                                for (var i = 0; i < commodities.length; i++) {
                                    var flag1 = '<tr><td>'+ commodities[i].commodityName +'</td><td>'+ commodities[i].specifications +'</td><td>'+ commodities[i].price +'</td><td>'+ commodities[i].count +'</td></tr>' 
                                }
                                flag += flag1
                                $("#commodities_info1").html(flag)
                            }
                              
                        }
                    })
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['66%', '90%'], //宽高
                        title: '预约订单详细',
                        btn: ['关闭'],
                        content: $('#orderDetails'),
                    });
                     
                }
            });
        
        
        });
        function dateTime(date) {
            if (date != '') {
                var dateTime = new Date(date).getTime()
            }else{
                var dateTime = ''
            }
            return dateTime
        }
        function ctime(num) {
            if (num == null) {
                var ctime = '订单未完成'
            }else {
                var ctime = layui.util.toDateString(Number(num), "yyyy.MM.dd HH:mm:ss")
            }
            return ctime
        }
        function status(num) {
            if(num == null) {
                var status = '订单未完成'
            }else {
                var status = num
            }
            return status
        }
        function orderstatusfun(num) {
            if (num == 0) {
                var orderstatus = '未付款'
            }else if (num == 1) {
                var orderstatus = '<span style="color: rgb(222, 130, 235);">未发货</span>'
            }else if (num == 2) {
                var orderstatus = '未取货'
            }else if (num == 3) {
                var orderstatus = '订单完成'
            }else{
                var orderstatus = '订单未完成'
            }
            return orderstatus
        }
        function paymethodfun(num) {
            if (num == '0') {
                var paymethod = '支付宝'
            }else if (num == '1'){
                var paymethod = '微信'
            }else {
                var paymethod = '其他支付方式'
            }
            return paymethod
        }
        
    </script>
</body>
</html>